import pygame, sys, math

class Blast(pygame.sprite.Sprite):
    def __init__(self, direction = "right", pos = (0,0)):
        pygame.sprite.Sprite.__init__(self, self.containers)
        self.baseImage = pygame.image.load("rsc/blast/Blast.png")
        self.speed = 30
        self.size = [10,10]
        #self.sizeGrowth = 1.1
        #self.damage = 100
        #self.damageDrain = 5
        self.heading = direction
        self.realx = pos[0]
        self.realy = pos[1]
        if self.heading == "left":
            self.baseImage = pygame.transform.flip(self.baseImage, 1, 0)
            self.realx -= 5
            self.realy -= 0
        if self.heading == "up":
            self.baseImage = pygame.transform.rotate(self.baseImage, 90)
            self.realx -= 0
            self.realy -= 5
        if self.heading == "down":
            self.baseImage = pygame.transform.rotate(self.baseImage, 270)
            self.realx -= 0
            self.realy += 5
        else:
            self.realx += 5
            self.realy -= 0
        self.image = pygame.transform.scale(self.baseImage, self.size)
        self.rect = self.image.get_rect()
        self.place([self.realx, self.realy])
        self.offsetx = 0
        self.offsety = 0
        self.life = 50
           
                                        
    def collideWall(self, width, height):
        if self.rect.left < 0 or self.rect.right > width:
            self.living = False  
        if self.rect.top < 0 or self.rect.bottom > height:
            self.living = False 


    
    def place(self, pos):
        self.rect.center = pos    
        
    def update(*args):
        self = args[0]
        self.playerspeedx = args[2]
        self.playerspeedy = args[3]
        self.scrollingx = args[4]
        self.scrollingy = args[5]
        self.move()
        #self.damage -= self.damageDrain
        #self.size = [self.size[0]*self.sizeGrowth, self.size[1]*self.sizeGrowth]
        #self.image = pygame.transform.scale(self.baseImage, [int(self.size[0]), int(self.size[1])])
        #self.rect = self.image.get_rect(center = self.rect.center)
        #if self.damage <= 0:
        #    self.kill()
        self.life -= 1
        if self.life <= 0:
            self.kill()
        
        
    def move(self):
        #print "enemy", self.realx, self.speedx
        if self.heading == "right":
            self.realx += self.speed
            self.realy += 0
        elif self.heading == "left":
            self.realx -= self.speed
            self.realy += 0
        elif self.heading == "up":
            self.realx += 0
            self.realy -= self.speed
        elif self.heading == "down":
            self.realx += 0
            self.realy += self.speed
       
            
        if self.scrollingx:
            self.offsetx -= self.playerspeedx
        if self.scrollingy:
            self.offsety -=  self.playerspeedy
        
        self.x = self.realx + self.offsetx
        self.y = self.realy + self.offsety
        
        print self.x, self.y
            
        self.rect.center = (round(self.x), round(self.y))